from flaskapp.util.Sqlalchemy import db

class Star(db.Model):
    __tablename__ = 'star'

    star_id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.user_id'), nullable=False)
    house_id = db.Column(db.Integer, db.ForeignKey('house.house_id'), nullable=False)
    created_at = db.Column(db.DateTime, default=db.func.current_timestamp())

    def __init__(self, user_id, house_id):
        self.user_id = user_id
        self.house_id = house_id

    def to_dict(self):
        return {
            'star_id': self.star_id,
            'user_id': self.user_id,
            'house_id': self.house_id,
            'created_at': self.created_at.isoformat() if self.created_at else None
        }